<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>命名路由</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="../js/vue-router.min.js"></script>

</head>
<body>
<div id="app">
    <!--刷新只能获取到id-->
    <router-link :to="{name:'user',params:{id:1,username:'tom',age:11}}">user1</router-link>
    <router-link :to="{name:'user',params:{id:2,username:'Jerry',age:12}}">user2</router-link>
    <router-link to="/login">Login</router-link>

    <router-view></router-view>
</div>
<script type="text/javascript">
    var User = {
        props:[
            'id','username','age'
        ],
        template:`<div>{{id+"-"+username+'-'+age}}</div> `
    }
    var Login = { template:"<div>This is Login</div>" }


    var router=new VueRouter({
        routes:[
            {path: "/user/:id", component: User,name:'user',
                props:route=>{
                    return {
                        username:route.params.username,
                        age:route.params.age,
                        id:route.params.id
                    }
                }
            },
            {path:'/login',component:Login},
        ]
    })

    var vm=new Vue({
        el:'#app',
        router
    })

</script>
</body>
</html>